/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import static Controller.FrameManager.centreWindow;
import DataAcces.DBAcces;
import java.util.List;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import static Controller.UserManager.*;
import GUI.PRINCIPAL;
import javax.swing.JOptionPane;

/**
 *
 * @author Promociones
 */
public class LoginManager {
    public static List UserData;
    public static boolean ValidLogin(JTextField User, JPasswordField Pass) {
        String Filter = "User = '"+User.getText()+"' and pass = '"+Pass.getText()+"'";
        List Reg = DBAcces.GetRegisterFiltered(UsersTable, Filter);
        
        if(!Reg.isEmpty()){
            for(int a=0;a<Reg.size();a++){
                Object[] data = (Object[]) Reg.get(a);
                for(int b=0;b<data.length;b++){
                    if(String.valueOf(data[1]).equals(User.getText()) 
                        && data[3].equals(Pass.getText())){
                        UserData = Reg;
                        PRINCIPAL p = new PRINCIPAL();
                        centreWindow(p);
                        p.setVisible(true);
                        return true;
                    }else{
                        JOptionPane.showMessageDialog(null, "Usiario o Contraseña no validos");
                        return false;
                    }
                }
            }
        }else{
            JOptionPane.showMessageDialog(null, "Usiario no Existe");
            return false;
        }
        return false;
    }
    
}
